import { defineStore } from "pinia/dist/pinia";

import { ref, reactive, computed } from "vue";


// defineStore第二参数是一个函数,该函数即为setup函数
export const useUserStore = defineStore("user", function () {

    const name = ref("张三");
    const age = ref(18);
    const grade = reactive({
        chinese: 55,
        math: 66,
        english: 77
    })

    const isGrowUp = computed(() => {
        return age.value >= 18;
    })

    const addAge = () => {
        age.value++
    }

    const reduceAge = () => {
        age.value--
    }

    const addChinese = () => {
        grade.chinese++
    }


    return {
        name,
        age,
        grade,
        isGrowUp,
        addAge,
        reduceAge,
        addChinese
    }
})
